package com.neborosoft.FlyingDog.logic.database.providers;

import com.neborosoft.FlyingDog.logic.database.AudioDataManager;
import com.neborosoft.lib.collections.tree.MultiStepsNavigationTree;

import java.util.List;

/**
 * Project: FlyingDog
 * User: stikhonenko
 * Date: 3/7/13
 * Time: 6:28 PM
 */
public abstract class TagsTreeWithSongsArtistsAndGenresNavigation extends MultiStepsNavigationTree{
    private static final AudioDataManager AUDIO_DATA_MANAGER = AudioDataManager.getInstance();

    public static final int LEVELS_COUNT = 5;
    public static final int TAGS_LEVEL = 0;
    public static final int GENRES_LEVEL = 1;
    public static final int ARTISTS_LEVEL = 2;
    public static final int ALBUMS_LEVEL = 3;
    public static final int STEPS_COUNT_FROM_TAGS_TO_SONGS = 3;
    public static final int STEPS_COUNT_FROM_TAGS_TO_ARTISTS = 1;

    public TagsTreeWithSongsArtistsAndGenresNavigation(){
        super(LEVELS_COUNT);
    }

    @Override
    protected List getChildrenOfParent(Object parent, int level, int stepsCount) {
        String tag = parent.toString();

        if(level == GENRES_LEVEL){
            return AUDIO_DATA_MANAGER.getTracksByTag(tag);
        } else if(level != TAGS_LEVEL){
            return ArtistTree.getChildrenOfParentInArtistTree(parent, level - 2, stepsCount);
        }

        if(stepsCount == STEPS_COUNT_FROM_TAGS_TO_SONGS){
            return AUDIO_DATA_MANAGER.getTracksByTag(tag);
        }

        if(stepsCount == STEPS_COUNT_FROM_TAGS_TO_ARTISTS){
            return AUDIO_DATA_MANAGER.getArtistsByTag(tag);
        }

        return AUDIO_DATA_MANAGER.getGenresOfCountry(tag);
    }
}
